﻿using System;
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TimKen.DataEntity;
using TimKen.BussLogic;
using System.Data;

namespace TimKen.Web.Admin.MessageBoard
{
    public partial class MessageBoard_View : TimKen.App.AdminPage
    {

        public DataEntity.MessageBoard message = new TimKen.DataEntity.MessageBoard();
        MessageBoardManager mbm = new MessageBoardManager();
        public override string ActionCode
        {
            get
            {
                return "30";//公司动态
            }
        }

        public int MessageID
        {
            get
            {
                if (ViewState["MessageID"] != null)
                    return Convert.ToInt32(ViewState["MessageID"]);
                else
                    return 0;
            }
            set
            {
                ViewState["MessageID"] = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            BindResources();
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["MessageID"] != null)
                {
                    MessageID = Convert.ToInt32(Request.QueryString["MessageID"]);
                }
            }
            if (MessageID != 0)
            {
                BindMessage();
                if (!IsPostBack)
                {
                    BindData();
                }
            }
        }


        protected void BindResources()
        {
            chkIsDisplay.Text = GetLangString("IsDisplay");
            btnSave.Text = GetLangString("Save");
        }

        private void BindMessage()
        {
            if (MessageID != 0)
            {
                message = mbm.GetModel(MessageID);
            }
        }

        private void BindData()
        {
            txtComments.Text = message.Comments;
            txtReplyContent.Text = message.ReplyContent;
            chkIsDisplay.Checked = message.IsDisplay;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            message.IsDisplay = chkIsDisplay.Checked;
            message.Comments = txtComments.Text;
            message.ReplyContent = txtReplyContent.Text;
            message.ReplierID = CurrentUserName;
            message.ReplyDate = DateTime.Now;
            mbm.Update(message);
            Response.Redirect("MessageBoard_List.aspx");

        }

    }
}

